using UnityEngine;
using System.Collections;

public class collisionCases : MonoBehaviour {
	
	public Rect startRect = new Rect( 500, 10, 200, 300);
	public bool allowDrag = true;
	
	public bool showCase1 = true;
	public bool showCase2 = true;
	public bool showCase3 = true;
	public bool showCase4 = true;
	public bool showCase5 = true;
	
	
	private GameObject coin1,coin2;
	private Vector3 coin1Angles = new Vector3(90,90,0);
	private Vector3 coin2Angles = new Vector3(70,90,0);
	private Vector3 coin1Position = new Vector3(0,0,0);
	private Vector3 coin2Position = new Vector3(0,35,0);
	
	private int sideLeft = 10;
	private int sideTop = 30;
	private int itemSpacing = 20;
	
	private string Case = "";
	
	private Color color = Color.white;
	private GUIStyle style;
	private int items = 0;
	
	
	// Use this for initialization
	void Start () {
	
		coin1 = GameObject.Find("coin1");
		coin2 = GameObject.Find("coin2");
		coin1.rigidbody.freezeRotation = true;
		coin2.rigidbody.freezeRotation = true;
		
		Initial();
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	
	void OnGUI (){
	
		if( style == null ){
			style = new GUIStyle( GUI.skin.label );
			style.normal.textColor = Color.white;
			style.alignment = TextAnchor.UpperCenter;
		}
 
		//GUI.color = updateColor ? color : Color.white;
		GUI.color = color;
		startRect = GUI.Window(1, startRect, doMyWindow, "");
	}
	
	
	
	void doMyWindow(int windowID)
	{
		// Make a background box
		GUI.Box(new Rect (0,0,startRect.width,startRect.height) , "collisionCase");
		
		items = 0;
		//Show testCase
		if (showCase1){
			//if(GUI.Button(new Rect(sideLeft,sideTop+items*itemSpacing*caseItemsSpacingScale , startRect.width*0.8F, startRect.height*0.08F), "Case1"))
			if(GUI.Button(new Rect(sideLeft,sideTop+items*itemSpacing , startRect.width*0.8F, startRect.height*0.1F), "Case1")) 
			{
				Case = "1";
				coin1Position = new Vector3(0,0,0);
				coin2Position = new Vector3(0,35,0);
				coin1Angles = new Vector3(90,90,0);
				coin2Angles = new Vector3(70,90,0);
				Initial();		
			}
			items++;
		}
		
		
		if (showCase2){
			//if(GUI.Button(new Rect(sideLeft,sideTop+items*itemSpacing*caseItemsSpacingScale, startRect.width*0.8F, startRect.height*0.08F), "Case2"))
			if(GUI.Button(new Rect(sideLeft,sideTop+items*itemSpacing+startRect.height*0.08F, startRect.width*0.8F, startRect.height*0.1F), "Case2"))
			{
				Case = "2";
				coin1Position = new Vector3(0,0,0);
				coin2Position = new Vector3(0,25,0);
				coin1Angles = new Vector3(0,0,0);
				coin2Angles = new Vector3(90,0,0);
				Initial();
			}
			items++;	
		}
		
		
		if (showCase3){
			if(GUI.Button(new Rect(sideLeft,sideTop+items*itemSpacing+startRect.height*0.08F*2, startRect.width*0.8F, startRect.height*0.1F), "Case3"))
			{
				Case = "3";
				coin1Position = new Vector3(0,0,0);
				coin2Position = new Vector3(0,35,0);
				coin1Angles = new Vector3(90,0,0);
				coin2Angles = new Vector3(90,45,0);
				Initial();
			}
			items++;	
		}
		
		
		if (showCase4){
			if(GUI.Button(new Rect(sideLeft,sideTop+items*itemSpacing+startRect.height*0.08F*3, startRect.width*0.8F, startRect.height*0.1F), "Case4"))
			{
				Case = "4";
				coin1Position = new Vector3(0,0,0);
				coin2Position = new Vector3(10,15,0);
				coin1Angles = new Vector3(0,0,0);
				coin2Angles = new Vector3(0,0,0);
				Initial();
			}
			items++;	
		}
		
		
		if (showCase5){
			if(GUI.Button(new Rect(sideLeft,sideTop+items*itemSpacing+startRect.height*0.08F*4, startRect.width*0.8F, startRect.height*0.1F), "Case5"))
			{
				Case = "5";
				coin1Position = new Vector3(0,0,0);
				coin2Position = new Vector3(0,35,0);
				coin1Angles = new Vector3(90,0,0);
				coin2Angles = new Vector3(90,90,0);
				Initial();
			}
			items++;	
		}
		// end show cases.
		
		
		
		if( allowDrag ) GUI.DragWindow(new Rect(0, 0, Screen.width, Screen.height));
	}
	
	
	public void Initial()
	{
		coin1.transform.position = coin1Position;
		coin2.transform.position = coin2Position;
		//coin1.rigidbody.velocity = new Vector3(0,0,0);
		coin2.rigidbody.velocity = new Vector3(0,0,0);
		coin1.transform.eulerAngles = coin1Angles;
		coin2.transform.eulerAngles = coin2Angles;
	}
	
}
